﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace Workflow.Project
{
    public partial class CustomerFree : System.Web.UI.Page
    {
        public PJOrderStart result = null;
        private PJOrderStartManager objPJOrderStartManager = new PJOrderStartManager();
        private WorkflowManager objWorkflowManager = new WorkflowManager();
        private UserTeamRoleManager objUserTeamRoleManager = new UserTeamRoleManager();
        public int workParentId;
        public int fromPage;
        public int childListCount;
        public int pjCount;
        public int statusNo;
        protected void Page_Load(object sender, EventArgs e)
        {
            workParentId = Convert.ToInt32(Request.QueryString["WorkParentId"]);
            fromPage = Convert.ToInt32(Request.QueryString["FromPage"]);
            if (!IsPostBack)
            {
                try
                {
                    pjCount = objUserTeamRoleManager.GetUserInfoTeam(Session["FullName"].ToString(), 10, 15) + objUserTeamRoleManager.GetUserInfoTeam(Session["FullName"].ToString(), 6, 15) + objUserTeamRoleManager.GetUserInfoTeam(Session["FullName"].ToString(), 7, 15) + objUserTeamRoleManager.GetUserInfoTeam(Session["FullName"].ToString(), 8, 15);
                    statusNo = objWorkflowManager.GetWorkflowStatues(workParentId);
                    result = objPJOrderStartManager.GetOrderStart(workParentId);
                    List<UserInfo> personList = objUserTeamRoleManager.GetUserInfo(6, 2, 15);
                    ViewState["statusNo"] = statusNo;
                    ddlPerson.DataSource = personList;
                    ddlPerson.DataTextField = "DisplayName";
                    ddlPerson.DataValueField = "UserName";
                    ddlPerson.DataBind();
                    if (result != null)
                    {
                        if (result.OrderType == "客户订单")
                        {
                            ddlOrderPurpose.Items[0].Text = "免费订单";
                            ddlOrderPurpose.Items[1].Text = "收费订单";
                        }
                        else
                        {
                            ddlOrderPurpose.Items[0].Text = "FOT首样";
                            ddlOrderPurpose.Items[1].Text = "DB修模";
                        }
                        txtSerialNum.Text = result.SerialNum;
                        ddlOrderType.SelectedItem.Text = result.OrderType;
                        ddlOrderPurpose.SelectedItem.Text = result.OrderPurpose;
                        if (!string.IsNullOrEmpty(result.Person)) { ddlPerson.SelectedItem.Text = result.Person; }
                        else 
                        { 
                            personList.Insert(0, new UserInfo() { UserName = "", DisplayName = "" });
                            ddlPerson.SelectedIndex = 0;
                            ddlPerson.DataBind();
                        }
                        txtData.Text = result.Statues;
                        txt0101.Text = result.ChildList[0].CustOrDepart;
                        txt0102.Text = result.ChildList[0].CustomerOrder;
                        txt0103.Text = result.ChildList[0].Maktx;
                        txt01Matnr.Text = result.ChildList[0].Matnr;
                        txt0104.Text = Convert.ToString(result.ChildList[0].Number);
                        txt0105.Text = result.ChildList[0].Mold;
                        txt0107.Text = result.ChildList[0].SapOrder;
                        txt0108.Text = result.ChildList[0].Ps;
                        childListCount = result.ChildList.Count;
                        if (result.ChildList.Count >= 2)
                        {
                            txt0201.Text = result.ChildList[1].CustOrDepart;
                            txt0202.Text = result.ChildList[1].CustomerOrder;
                            txt0203.Text = result.ChildList[1].Maktx;
                            txt02Matnr.Text = result.ChildList[1].Matnr;
                            txt0204.Text = Convert.ToString(result.ChildList[1].Number);
                            txt0205.Text = result.ChildList[1].Mold;
                            txt0207.Text = result.ChildList[1].SapOrder;
                            txt0208.Text = result.ChildList[1].Ps;
                        }
                        if (result.ChildList.Count >= 3)
                        {
                            txt0301.Text = result.ChildList[2].CustOrDepart;
                            txt0302.Text = result.ChildList[2].CustomerOrder;
                            txt0303.Text = result.ChildList[2].Maktx;
                            txt03Matnr.Text = result.ChildList[2].Matnr;
                            txt0304.Text = Convert.ToString(result.ChildList[2].Number);
                            txt0305.Text = result.ChildList[2].Mold;
                            txt0307.Text = result.ChildList[2].SapOrder;
                            txt0308.Text = result.ChildList[2].Ps;
                        }
                        if (result.ChildList.Count >= 4)
                        {
                            txt0401.Text = result.ChildList[3].CustOrDepart;
                            txt0402.Text = result.ChildList[3].CustomerOrder;
                            txt0403.Text = result.ChildList[3].Maktx;
                            txt04Matnr.Text = result.ChildList[3].Matnr;
                            txt0404.Text = Convert.ToString(result.ChildList[3].Number);
                            txt0405.Text = result.ChildList[3].Mold;
                            txt0407.Text = result.ChildList[3].SapOrder;
                            txt0408.Text = result.ChildList[3].Ps;
                        }
                        if (result.ChildList.Count >= 5)
                        {
                            txt0501.Text = result.ChildList[4].CustOrDepart;
                            txt0502.Text = result.ChildList[4].CustomerOrder;
                            txt0503.Text = result.ChildList[4].Maktx;
                            txt05Matnr.Text = result.ChildList[4].Matnr;
                            txt0504.Text = Convert.ToString(result.ChildList[4].Number);
                            txt0505.Text = result.ChildList[4].Mold;
                            txt0507.Text = result.ChildList[4].SapOrder;
                            txt0508.Text = result.ChildList[4].Ps;
                        }
                        if (result.ChildList.Count >= 6)
                        {
                            txt0601.Text = result.ChildList[5].CustOrDepart;
                            txt0602.Text = result.ChildList[5].CustomerOrder;
                            txt0603.Text = result.ChildList[5].Maktx;
                            txt06Matnr.Text = result.ChildList[5].Matnr;
                            txt0604.Text = Convert.ToString(result.ChildList[5].Number);
                            txt0605.Text = result.ChildList[5].Mold;
                            txt0607.Text = result.ChildList[5].SapOrder;
                            txt0608.Text = result.ChildList[5].Ps;
                        }
                        if (result.ChildList.Count >= 7)
                        {
                            txt0701.Text = result.ChildList[6].CustOrDepart;
                            txt0702.Text = result.ChildList[6].CustomerOrder;
                            txt0703.Text = result.ChildList[6].Maktx;
                            txt07Matnr.Text = result.ChildList[6].Matnr;
                            txt0704.Text = Convert.ToString(result.ChildList[6].Number);
                            txt0705.Text = result.ChildList[6].Mold;
                            txt0707.Text = result.ChildList[6].SapOrder;
                            txt0708.Text = result.ChildList[6].Ps;
                        }
                        if (result.ChildList.Count >= 8)
                        {
                            txt0801.Text = result.ChildList[7].CustOrDepart;
                            txt0802.Text = result.ChildList[7].CustomerOrder;
                            txt0803.Text = result.ChildList[7].Maktx;
                            txt08Matnr.Text = result.ChildList[7].Matnr;
                            txt0804.Text = Convert.ToString(result.ChildList[7].Number);
                            txt0805.Text = result.ChildList[7].Mold;
                            txt0807.Text = result.ChildList[7].SapOrder;
                            txt0808.Text = result.ChildList[7].Ps;
                        }
                        if (result.ChildList.Count >= 9)
                        {
                            txt0901.Text = result.ChildList[8].CustOrDepart;
                            txt0902.Text = result.ChildList[8].CustomerOrder;
                            txt0903.Text = result.ChildList[8].Maktx;
                            txt09Matnr.Text = result.ChildList[8].Matnr;
                            txt0904.Text = Convert.ToString(result.ChildList[8].Number);
                            txt0905.Text = result.ChildList[8].Mold;
                            txt0907.Text = result.ChildList[8].SapOrder;
                            txt0908.Text = result.ChildList[8].Ps;
                        }
                        if (result.ChildList.Count >= 10)
                        {
                            txt1001.Text = result.ChildList[9].CustOrDepart;
                            txt1002.Text = result.ChildList[9].CustomerOrder;
                            txt1003.Text = result.ChildList[9].Maktx;
                            txt10Matnr.Text = result.ChildList[9].Matnr;
                            txt1004.Text = Convert.ToString(result.ChildList[9].Number);
                            txt1005.Text = result.ChildList[9].Mold;
                            txt1007.Text = result.ChildList[9].SapOrder;
                            txt1008.Text = result.ChildList[9].Ps;
                        }
                        if(fromPage==0 || statusNo!=100)
                        {
                            if (pjCount > 0 && statusNo < 1) //项目或销售
                            {
                                EnabledControl2();
                                ddlPerson.Enabled = true;
                                Update1.Visible = true;
                            }
                            if (pjCount > 0 && statusNo == 2) //项目
                            {
                                EnabledControl4();
                                Update2.Visible = true;
                            }
                            if (pjCount > 0 && statusNo == 3)
                            {
                                EnabledControl3();
                                Update2.Visible = true;
                            }
                            if (pjCount > 0 && statusNo == 4)
                            {
                                BtnSubmit2.Visible = true;
                            }
                        }
                        if (statusNo == 100) //已完成
                        {
                            BtnSubmit2.Visible = true;
                        }
                        

                    }
                    else
                    {

                        if (statusNo == 0)

                        {
                            personList.Insert(0, new UserInfo() { UserName = "", DisplayName = "" });
                            ddlPerson.DataBind();
                            EnabledControl1();
                            EnabledControl2();
                            BtnSubmit1.Visible = true;
                        }

                        
                        
                    }
                }
                catch (Exception ex)
                {
                    string msg = string.Format("<script>alert('{0}');</script>", ex.Message.ToString());
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                }
            }

        }

        protected void BtnSubmit1_Click(object sender, EventArgs e)
        {
            if (ddlOrderType.SelectedValue == "0")
            {
                ddlOrderPurpose.Items[0].Text = "免费订单";
                ddlOrderPurpose.Items[1].Text = "收费订单";
            }
            else
            {
                ddlOrderPurpose.Items[0].Text = "FOT首样";
                ddlOrderPurpose.Items[1].Text = "DB修模";
            }
            try
            {
                PJOrderStart objPJOrderStartCreate = new PJOrderStart()
                {
                    WorkParentId = workParentId,
                    SerialNum = ddlOrderType.SelectedValue + ddlOrderPurpose.SelectedValue,
                    OrderType = ddlOrderType.SelectedItem.Text,
                    OrderPurpose = ddlOrderPurpose.SelectedItem.Text,
                    Person = ddlPerson.SelectedItem.Text,
                    ChildList = new List<PJOrderChildStart>()
                };
                GetInfo(ref objPJOrderStartCreate);
                string result = objPJOrderStartManager.InsertIsNoSucess(objPJOrderStartCreate);
                if(result!="false")
                {
                    string msg = string.Format("<script>alert('流水号:{0}保存成功！')</script>", result);
                    string str = string.Format("<script>window.close();</script>");
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "", str);
                }
                else
                {
                    string msg = string.Format("<script>alert('保存失败！')</script>", result);
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                }

            }
            catch (Exception ex)
            {
                string msg = string.Format("<script>alert('{0}');</script>", ex.Message.ToString());
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
            }
        }
        private string ShowDate(string id, string date, string strTemp)
        {
            string str = "";
            if (date != "1900-01-01")
            {
                str = strTemp + string.Format("document.getElementById('{0}').value = '{1}';", id, date);
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "", str);
            }
            return str;

        }

        protected void BtnSubmit2_Click(object sender, EventArgs e)
        {
            try
            {
                objPJOrderStartManager.UpdateStatues(workParentId);
                string msg = string.Format("<script>alert('同步成功！')</script>");
                string str = string.Format("<script>window.close();</script>");
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", str);
            }
            catch (Exception ex)
            {
                string msg = string.Format("<script>alert('{0}');</script>", ex.Message.ToString());
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
            }
        }

        protected void Update1_Click(object sender, EventArgs e)//项目或销售更改
        {
            PJOrderStart objPJOrderStartUpdate = new PJOrderStart()
            {
                WorkParentId = workParentId,
                SerialNum = txtSerialNum.Text.ToString().Trim(),
                Person = ddlPerson.SelectedItem.Text,
                ChildList = new List<PJOrderChildStart>()
            };
            GetInfo(ref objPJOrderStartUpdate);
            try
            {
                objPJOrderStartManager.UpdateInfo(objPJOrderStartUpdate);
                string msg = string.Format("<script>alert('保存成功！')</script>");
                string str = string.Format("<script>window.close();</script>");
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", str);
            }
            catch (Exception ex)
            {
                string msg = string.Format("<script>alert('{0}');</script>", ex.Message.ToString());
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
            }
        }
        protected void Update2_Click(object sender, EventArgs e) //项目更改
        {
            PJOrderStart objOrderStartUpdate = new PJOrderStart()
            {
                ChildList = new List<PJOrderChildStart>()
            };
            objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 1,
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    Matnr = txt01Matnr.Text.ToString().Trim(),
                    ConfirmDate = Request.Params.Get("txt0106") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0106")),
                    SapOrder = txt0107.Text.Trim().ToString()
                });
            if (txt0201.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 2,
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    Matnr = txt02Matnr.Text.ToString().Trim(),
                    ConfirmDate = Request.Params.Get("txt0206") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0206")),
                    SapOrder = txt0207.Text.Trim().ToString()
                });
            }
            if (txt0301.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 3,
                    Matnr = txt03Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt0306") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0306")),
                    SapOrder = txt0307.Text.Trim().ToString()
                });
            }
            if (txt0401.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 4,
                    Matnr = txt04Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt0406") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0406")),
                    SapOrder = txt0407.Text.Trim().ToString()
                });
            }
            if (txt0501.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 5,
                    Matnr = txt05Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt0506") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0506")),
                    SapOrder = txt0507.Text.Trim().ToString()
                });
            }
            if (txt0601.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 6,
                    Matnr = txt06Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt0606") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0606")),
                    SapOrder = txt0607.Text.Trim().ToString()
                });
            }
            if (txt0701.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 7,
                    Matnr = txt07Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt0706") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0706")),
                    SapOrder = txt0707.Text.Trim().ToString()
                });
            }
            if (txt0801.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 8,
                    Matnr = txt08Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt0806") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0806")),
                    SapOrder = txt0807.Text.Trim().ToString()
                });
            }
            if (txt0901.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 9,
                    Matnr = txt09Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt0906") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0906")),
                    SapOrder = txt0907.Text.Trim().ToString()
                });
            }
            if (txt1001.Text.Trim().ToString().Length > 0)
            {
                objOrderStartUpdate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 10,
                    Matnr = txt10Matnr.Text.ToString().Trim(),
                    SerialNum = txtSerialNum.Text.Trim().ToString(),
                    ConfirmDate = Request.Params.Get("txt1006") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt1006")),
                    SapOrder = txt1007.Text.Trim().ToString()
                });
            }
            try
            {
                statusNo = Convert.ToInt32(ViewState["statusNo"]) ;
                foreach (var item in objOrderStartUpdate.ChildList)
                {
                    if (statusNo == 2)
                    {
                        objPJOrderStartManager.UpdateDate(item.ConfirmDate, item.Matnr, item.SerialNum, item.Row);
                    }
                    else if (statusNo == 3)
                    {
                        objPJOrderStartManager.UpdateSapOrder(item.SapOrder, item.SerialNum, item.Row);
                    }

                }
                string msg = string.Format("<script>alert('保存成功！')</script>");
                string str = string.Format("<script>window.close();</script>");
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", str);
            }
            catch (Exception ex)
            {
                string msg = string.Format("<script>alert('{0}');</script>", ex.Message.ToString());
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
            }
        }
        void EnabledControl1()
        {
            ddlOrderType.Enabled = true;
            ddlOrderPurpose.Enabled = true;
            ddlPerson.Enabled = true;
        }
        void EnabledControl2()
        {
            txt0101.Enabled = true;
            txt0102.Enabled = true;
            txt0103.Enabled = true;
            txt0104.Enabled = true;
            txt0105.Enabled = true;
            txt0108.Enabled = true;
            txt0201.Enabled = true;
            txt0202.Enabled = true;
            txt0203.Enabled = true;
            txt0204.Enabled = true;
            txt0205.Enabled = true;
            txt0208.Enabled = true;
            txt0301.Enabled = true;
            txt0302.Enabled = true;
            txt0303.Enabled = true;
            txt0304.Enabled = true;
            txt0305.Enabled = true;
            txt0308.Enabled = true;
            txt0401.Enabled = true;
            txt0402.Enabled = true;
            txt0403.Enabled = true;
            txt0404.Enabled = true;
            txt0405.Enabled = true;
            txt0408.Enabled = true;
            txt0501.Enabled = true;
            txt0502.Enabled = true;
            txt0503.Enabled = true;
            txt0504.Enabled = true;
            txt0505.Enabled = true;
            txt0508.Enabled = true;
            txt0601.Enabled = true;
            txt0602.Enabled = true;
            txt0603.Enabled = true;
            txt0604.Enabled = true;
            txt0605.Enabled = true;
            txt0608.Enabled = true;
            txt0701.Enabled = true;
            txt0702.Enabled = true;
            txt0703.Enabled = true;
            txt0704.Enabled = true;
            txt0705.Enabled = true;
            txt0708.Enabled = true;
            txt0801.Enabled = true;
            txt0802.Enabled = true;
            txt0803.Enabled = true;
            txt0804.Enabled = true;
            txt0805.Enabled = true;
            txt0808.Enabled = true;
            txt0901.Enabled = true;
            txt0902.Enabled = true;
            txt0903.Enabled = true;
            txt0904.Enabled = true;
            txt0905.Enabled = true;
            txt0908.Enabled = true;
            txt1001.Enabled = true;
            txt1002.Enabled = true;
            txt1003.Enabled = true;
            txt1004.Enabled = true;
            txt1005.Enabled = true;
            txt1008.Enabled = true;
            txt01Matnr.Enabled = true;
            txt02Matnr.Enabled = true;
            txt03Matnr.Enabled = true;
            txt04Matnr.Enabled = true;
            txt05Matnr.Enabled = true;
            txt06Matnr.Enabled = true;
            txt07Matnr.Enabled = true;
            txt08Matnr.Enabled = true;
            txt09Matnr.Enabled = true;
            txt10Matnr.Enabled = true;
        }
        void EnabledControl3()
        {
            txt0107.Enabled = true;
            txt0207.Enabled = true;
            txt0307.Enabled = true;
            txt0407.Enabled = true;
            txt0507.Enabled = true; 
            txt0607.Enabled = true;
            txt0707.Enabled = true;
            txt0807.Enabled = true;
            txt0907.Enabled = true;
            txt1007.Enabled = true;
        }
        void EnabledControl4()
        {
            txt01Matnr.Enabled = true;
            txt02Matnr.Enabled = true;
            txt03Matnr.Enabled = true;
            txt04Matnr.Enabled = true;
            txt05Matnr.Enabled = true;
            txt06Matnr.Enabled = true;
            txt07Matnr.Enabled = true;
            txt08Matnr.Enabled = true;
            txt09Matnr.Enabled = true;
            txt10Matnr.Enabled = true;
        }


        void GetInfo(ref PJOrderStart objPJOrderStartCreate)
        {
            if (txt0101.Text.Trim().ToString().Length > 0)
            {

                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 1,
                    CustOrDepart = txt0101.Text.Trim().ToString(),
                    CustomerOrder = txt0102.Text.Trim().ToString(),
                    Maktx = txt0103.Text.Trim().ToString(),
                    Matnr = txt01Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0104.Text.Trim().ToString()),
                    Mold = txt0105.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0106") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0106")),
                    SapOrder = txt0107.Text.Trim().ToString(),
                    Ps = txt0108.Text.Trim().ToString()
                });
            }
            if (txt0201.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 2,
                    CustOrDepart = txt0201.Text.Trim().ToString(),
                    CustomerOrder = txt0202.Text.Trim().ToString(),
                    Maktx = txt0203.Text.Trim().ToString(),
                    Matnr = txt02Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0204.Text.Trim().ToString()),
                    Mold = txt0205.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0206") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0206")),
                    SapOrder = txt0207.Text.Trim().ToString(),
                    Ps = txt0208.Text.Trim().ToString()
                });
            }
            if (txt0301.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 3,
                    CustOrDepart = txt0301.Text.Trim().ToString(),
                    CustomerOrder = txt0302.Text.Trim().ToString(),
                    Maktx = txt0303.Text.Trim().ToString(),
                    Matnr = txt03Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0304.Text.Trim().ToString()),
                    Mold = txt0305.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0306") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0306")),
                    SapOrder = txt0307.Text.Trim().ToString(),
                    Ps = txt0308.Text.Trim().ToString()
                });
            }
            if (txt0401.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 4,
                    CustOrDepart = txt0401.Text.Trim().ToString(),
                    CustomerOrder = txt0402.Text.Trim().ToString(),
                    Maktx = txt0403.Text.Trim().ToString(),
                    Matnr = txt04Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0404.Text.Trim().ToString()),
                    Mold = txt0405.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0406") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0406")),
                    SapOrder = txt0407.Text.Trim().ToString(),
                    Ps = txt0408.Text.Trim().ToString()
                });
            }
            if (txt0501.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 5,
                    CustOrDepart = txt0501.Text.Trim().ToString(),
                    CustomerOrder = txt0502.Text.Trim().ToString(),
                    Maktx = txt0503.Text.Trim().ToString(),
                    Matnr = txt05Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0504.Text.Trim().ToString()),
                    Mold = txt0505.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0506") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0506")),
                    SapOrder = txt0507.Text.Trim().ToString(),
                    Ps = txt0508.Text.Trim().ToString()
                });
            }
            if (txt0601.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 6,
                    CustOrDepart = txt0601.Text.Trim().ToString(),
                    CustomerOrder = txt0602.Text.Trim().ToString(),
                    Maktx = txt0603.Text.Trim().ToString(),
                    Matnr = txt06Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0604.Text.Trim().ToString()),
                    Mold = txt0605.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0606") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0606")),
                    SapOrder = txt0607.Text.Trim().ToString(),
                    Ps = txt0608.Text.Trim().ToString()
                });
            }
            if (txt0701.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 7,
                    CustOrDepart = txt0701.Text.Trim().ToString(),
                    CustomerOrder = txt0702.Text.Trim().ToString(),
                    Maktx = txt0703.Text.Trim().ToString(),
                    Matnr = txt07Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0704.Text.Trim().ToString()),
                    Mold = txt0705.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0706") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0706")),
                    SapOrder = txt0707.Text.Trim().ToString(),
                    Ps = txt0708.Text.Trim().ToString()
                });
            }
            if (txt0801.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 8,
                    CustOrDepart = txt0801.Text.Trim().ToString(),
                    CustomerOrder = txt0802.Text.Trim().ToString(),
                    Maktx = txt0803.Text.Trim().ToString(),
                    Matnr = txt08Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0804.Text.Trim().ToString()),
                    Mold = txt0805.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0806") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0806")),
                    SapOrder = txt0807.Text.Trim().ToString(),
                    Ps = txt0808.Text.Trim().ToString()
                });
            }
            if (txt0901.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 9,
                    CustOrDepart = txt0901.Text.Trim().ToString(),
                    CustomerOrder = txt0902.Text.Trim().ToString(),
                    Maktx = txt0903.Text.Trim().ToString(),
                    Matnr = txt09Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt0904.Text.Trim().ToString()),
                    Mold = txt0905.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt0906") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt0906")),
                    SapOrder = txt0907.Text.Trim().ToString(),
                    Ps = txt0908.Text.Trim().ToString()
                });
            }
            if (txt1001.Text.Trim().ToString().Length > 0)
            {
                objPJOrderStartCreate.ChildList.Add(new PJOrderChildStart()
                {
                    Row = 10,
                    CustOrDepart = txt1001.Text.Trim().ToString(),
                    CustomerOrder = txt1002.Text.Trim().ToString(),
                    Maktx = txt1003.Text.Trim().ToString(),
                    Matnr = txt10Matnr.Text.Trim().ToString(),
                    Number = Convert.ToInt32(txt1004.Text.Trim().ToString()),
                    Mold = txt1005.Text.Trim().ToUpper().ToString(),
                    ConfirmDate = Request.Params.Get("txt1006") == "" ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(Request.Params.Get("txt1006")),
                    SapOrder = txt1007.Text.Trim().ToString(),
                    Ps = txt1008.Text.Trim().ToString()
                });
            }
        }


    }
}